package gui;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JMenu;
import javax.swing.JMenuBar;
import javax.swing.JMenuItem;

import controller.FileController;
import controller.PlotController;

public class MenuBar extends JMenuBar implements ActionListener {

	private static final long serialVersionUID = 1L;

	public MenuBar() {
		super();
		this.initialize();
	}

	private void initialize() {
		this.file = new JMenu("File");
		this.edit = new JMenu("Edit");
		this.source = new JMenu("Source");

		for (JMenuItem item : fileItem) {
			this.file.add(item);
			item.addActionListener(this);
		}

		for (JMenuItem item : sourceItem) {
			this.source.add(item);
			item.addActionListener(this);
		}

		this.add(file);
		this.add(edit);
		this.add(source);

	}

	public void actionPerformed(ActionEvent e) {
		// TODO Auto-generated method stub
		JMenuItem temp = (JMenuItem) e.getSource();
		if (temp == fileItem[0]) {
			FileController.getInstance().newFile();
		} else if (temp == fileItem[1]) { // open file
			FileController.getInstance().openFile();
		} else if (temp == sourceItem[0]) {
			
		} else if (temp == fileItem[3]) { // save as file
			FileController.getInstance().saveAsFile();
		} else if (temp == fileItem[2]) {
			FileController.getInstance().saveFile();
		} else if (temp == fileItem[4]) {
			//FileController.getInstance().newPlot();
			PlotController.getInstance().plotData();
		}
	}

	private JMenu file = null;
	private JMenu edit = null;
	private JMenu source = null;

	private JMenuItem[] fileItem = { new JMenuItem("New..."),
			new JMenuItem("Open File..."), new JMenuItem("Save"),
			new JMenuItem("Save As..."), new JMenuItem("Plot") };
	private JMenuItem[] sourceItem = { new JMenuItem("Token Analysis") };
}
